/*
 * ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
 * Without permission, no one has the right to obtain, disclose or use this software in any way.
 */
package com.ecarx.systemui.plugin.ui.statusbar

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.core.content.res.ResourcesCompat
import com.ecarx.systemui.plugin.PluginContext
import com.ecarx.systemui.plugin.R
import com.ecarx.systemui.plugin.controller.GPSSController
import com.ecarx.systemui.plugin.ui.custom.SystemBarButton
import com.ecarx.systemui.plugin.ui.dialog.base.DialogManager
import com.ecarx.systemui.plugin.utils.LogUtils

class GpsView : SystemBarButton {

    constructor(context: Context?) : this(context!!, null) {}
    constructor(context: Context?, attrs: AttributeSet?) : this(context!!, attrs, 0) {}
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context!!,
        attrs,
        defStyleAttr
    ) {

    }

    override fun getContentDescriptionString(): String {
        return "GpsView"
    }

    override fun initView() {
        super.initView()

        setImageDrawable(
            ResourcesCompat
                .getDrawable(
                    resources,
                    R.drawable.ic_status_icon_gps_nosignal,
                    context.theme
                )
        )
        visibility = View.GONE
        setOnClickListener { v: View? ->
            DialogManager.getDialogManager().showGPSDialog(PluginContext.getInstance().pluginContext, true)
        }

        GPSSController.getInstance(PluginContext.getInstance().pluginContext).setIOnNotifyGpsIconChangeListener {
            LogUtils.i("GPSSController GpsView it = >>> ", it.toString())
            if (it > 0) {
                this.visibility = View.VISIBLE
                setImageDrawable(
                    ResourcesCompat
                        .getDrawable(
                            resources,
                            it,
                            context.theme
                        )
                )
            } else {
                this.visibility = View.GONE
            }
        }
    }

    override fun onFinishInflate() {
        super.onFinishInflate()


    }

    fun setIcon() {

    }
}